/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.classic.Session;
import pojo.SanPham;
import pojo.SanPham;
import util.HibernateUtil;

/**
 *
 * @author OSIRIS
 */
public class SanPhamDAO extends AbstractDAO{

 public static List<SanPham> TimKiem(String tensp,int madm) throws HibernateException{
      List<SanPham> ds=null;
        Session session=HibernateUtil.getSessionFactory().openSession();
       
            
            String hql="select sp from SanPham sp where sp.tenSanPham like:tensp and sp.danhMuc=:madm";
            Query query=session.createQuery(hql);
            query.setString("tensp","%"+ tensp+"%");
            query.setInteger("madm", madm);
            ds=query.list();
       
        
        return ds;
     
 }
   public SanPhamDAO() {
        super();
    }

    /**
     * Insert a new SanPham into the database.
     * @param info
     */
    public void create(SanPham info) throws DataAccessLayerException {
        super.saveOrUpdate(info);
    }


    /**
     * Delete a detached SanPham from the database.
     * @param info
     */
    public void delete(SanPham info) throws DataAccessLayerException {
        super.delete(info);
    }

    /**
     * Find an SanPham by its primary key.
     * @param id
     * @return
     */
    public SanPham find(Integer id) throws DataAccessLayerException {
        return (SanPham) super.find(SanPham.class, id);
    }

    /**
     * Updates the state of a detached SanPham.
     *
     * @param info
     */
    public void update(SanPham info) throws DataAccessLayerException {
        super.saveOrUpdate(info);
    }

    /**
     * Finds all SanPhams in the database.
     * @return
     */
    public List findAll() throws DataAccessLayerException{
        return super.findAll(SanPham.class);
    }
}
